package com.jeedroid.weibo.oauth;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;

import android.util.Log;



/**
 * 以同步方式发送http请求 
 * @author jeedroid
 *
 */
public class SyncHttp
{
	private HttpParams httpParameters;  
	private HttpClient httpClient;
	public SyncHttp()
	{
		httpParameters=new BasicHttpParams();
		HttpConnectionParams.setSoTimeout(httpParameters, 5000);
		httpClient=new DefaultHttpClient(httpParameters);
	}
/**
 * 以get方式发送请求
 * @param url url地址
 * @param params 发送参数
 * @return
 */
public String httpGet(String url,String params)
{
	if(null!=params&&!params.equals(""))
	{
		url+="?"+params;
	}
	HttpGet getMethod=new HttpGet(url);
	//设置请求超时时间
		try
		{
			HttpResponse response =httpClient.execute(getMethod);
			if(response.getStatusLine().getStatusCode()==HttpStatus.SC_OK)
			{
				 String str = EntityUtils.toString(response.getEntity());
				 return str;
			}
			else
			{
				Log.i("SyncHttp", "get method failed!");
			}
		} catch (ClientProtocolException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParseException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
}
}
